//
//  ROCustomNoNetworkEmptyView.m
//  Runone
//
//  Created by runone02 on 16/12/17.
//  Copyright © 2016年 runone. All rights reserved.
//

#import "ROCustomNoNetworkEmptyView.h"
#import "AppConstants.h"
#import "UIView+Addition.h"
/***  当前屏幕宽度 */
#define kScreenWidth  [[UIScreen mainScreen] bounds].size.width
/***  当前屏幕高度 */
#define kScreenHeight   [UIScreen mainScreen].bounds.size.height

@interface ROCustomNoNetworkEmptyView()

@property (nonatomic, weak) UIImageView *topTipImageView; //提示没网络的图片

@property (nonatomic, weak) UIButton *retryBtn;           //重新加载按钮

@end

@implementation ROCustomNoNetworkEmptyView

#pragma mark - lazy load
- (UIImageView *)topTipImageView {
    if (!_topTipImageView) {
        UIImageView *img = [[UIImageView alloc]init];
        [self addSubview:img];
        _topTipImageView                     = img;
        _topTipImageView.layer.masksToBounds = YES;
        _topTipImageView.backgroundColor     = kCommonBgColor;
    }
    return _topTipImageView;
}

- (UIButton *)retryBtn {
    if (!_retryBtn) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:btn];
        _retryBtn = btn;
        _retryBtn.backgroundColor = kOrangeColor;
        [_retryBtn setTitle:@"马上重试" forState:UIControlStateNormal];
        [_retryBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
        _retryBtn.titleLabel.font = kFont(15);
        [_retryBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        _retryBtn.adjustsImageWhenDisabled    = NO;
        _retryBtn.adjustsImageWhenHighlighted = NO;
    }
    return _retryBtn;
}
#pragma mark -点击马上重试按钮
- (void)btnClick:(UIButton *)btn {
    if (self.ROCustomNoNetworkEmptyViewDidClickRetryHandle) {
        self.ROCustomNoNetworkEmptyViewDidClickRetryHandle(self);
    }
}

- (void)layoutSubviews {
    CGFloat topTipImgVW = 150;
    CGFloat topTipImgVH = 100;
    CGFloat topTipImgX = kScreenWidth  / 2.0 - topTipImgVW / 2.0;
    CGFloat topTipImgY = kScreenHeight / 2.0 - topTipImgVH / 2.0;
    _topTipImageView.frame = CGRectMake(topTipImgX, topTipImgY, topTipImgVW, topTipImgVH);
    
    CGFloat retryW = 60;
    CGFloat retryH = 25;
    CGFloat retryX =  _topTipImageView.centerX - 30;
    CGFloat retryY =  _topTipImageView.bottom  + 15;
    _retryBtn.frame = CGRectMake(retryX, retryY, retryW, retryH);
}
@end
